// 引入所有需要的 worker
import jsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";
import cssWorker from "monaco-editor/esm/vs/language/css/css.worker?worker";
import htmlWorker from "monaco-editor/esm/vs/language/html/html.worker?worker";
import tsWorker from "monaco-editor/esm/vs/language/typescript/ts.worker?worker";
import EditorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";

export function initializeMonacoWorkers() {
    // 设置全局的环境对象，用于配置如何加载 workers
    self.MonacoEnvironment = {
        getWorker(_, label) {
            if (label === "json") {
                return new jsonWorker();
            }
            if (["css", "scss", "less"].includes(label)) {
                return new cssWorker();
            }
            if (["html", "handlebars", "razor"].includes(label)) {
                return new htmlWorker();
            }
            if (["typescript", "javascript"].includes(label)) {
                return new tsWorker();
            }
            return new EditorWorker();
        },
    };
}